// 绑定一起使用，就不必分开来拉size和pos了！
class ScrollList extends eui.Component implements eui.UIComponent {
	public constructor() {
		super();
        this.skinName = 'scrolllist';
    }

    list: eui.List;

	scroller: eui.Scroller;

	protected override childrenCreated(): void {
		super.childrenCreated();
        this.scroller.viewport = this.list;
		this.scroller.scrollPolicyH = eui.ScrollPolicy.OFF;
		this.scroller.scrollPolicyV = eui.ScrollPolicy.ON;
	}

	scrollToEnd(): void{
		this.list.scrollV = this.list.contentHeight - this.list.height;
	}

	isScrollToEnd(): boolean {
		return this.list.scrollV + this.list.height >= this.list.contentHeight;
	}

	addItemCheckEnd(item: any): void{
		if (this.list.dataProvider instanceof eui.ArrayCollection) {
			const oldv = this.list.scrollV;
			const end = this.isScrollToEnd();
			this.list.dataProvider.addItem(item);
			if (end) {
				nextFrame(() => this.scrollToEnd(), null);
			}
			// ui.msglog(oldv, end, this.list.scrollV);
		}
	}
}
